package cn.yhjz.generator.service.impl;

import cn.yhjz.common.Pager;
import cn.yhjz.generator.entity.SysGenProject;
import cn.yhjz.generator.service.ISysGenProjectService;
import cn.yhjz.generator.vo.SysGenProjectVo;
import cn.yhjz.generator.mapper.SysGenProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = {Exception.class})
public class SysGenProjectServiceImpl implements ISysGenProjectService {

    @Autowired
    private SysGenProjectMapper sysGenProjectMapper;


    @Override
    public Pager getPage(Long currentPage, Long pageSize, SysGenProject sysGenProject) {
        Pager pager = new Pager();
        Long count = sysGenProjectMapper.getPageCount(sysGenProject);
        Long pageOffset = (currentPage - 1) * pageSize;
        List<SysGenProjectVo> records = sysGenProjectMapper.getPage(pageOffset, pageSize, sysGenProject);
        pager.setRows(records);
        pager.setCurrentPage(currentPage);
        pager.setPageSize(pageSize);
        pager.setTotalPageCount(count);
        return pager;
    }

    @Override
    public SysGenProject insert(SysGenProject sysGenProject) {
        int res = sysGenProjectMapper.insert(sysGenProject);
        if(res > 0){
            return sysGenProject;
        }else{
            return null;
        }
    }

    @Override
    public List<SysGenProject> select(SysGenProject sysGenProject) {
        return sysGenProjectMapper.select(sysGenProject);
    }

    @Override
    public List<SysGenProjectVo> selectVo(SysGenProject sysGenProject) {
        return sysGenProjectMapper.selectVo(sysGenProject);
    }

    @Override
    public SysGenProject selectOne(SysGenProject sysGenProject) {
        return sysGenProjectMapper.selectOne(sysGenProject);
    }

    @Override
    public SysGenProjectVo selectOneVo(SysGenProject sysGenProject) {
        return sysGenProjectMapper.selectOneVo(sysGenProject);
    }

    @Override
    public SysGenProjectVo selectById(Long id) {
        return sysGenProjectMapper.selectById(id);
    }

    @Override
    public int deleteById(Long id) {
        return sysGenProjectMapper.deleteById(id);
    }

    @Override
    public int updateByIdWithNull(SysGenProject sysGenProject) {
        return sysGenProjectMapper.updateByIdWithNull(sysGenProject);
    }

    @Override
    public int updateById(SysGenProject sysGenProject) {
        return sysGenProjectMapper.updateById(sysGenProject);
    }

    @Override
    public int update(SysGenProject entity, SysGenProject param) {
        return sysGenProjectMapper.update(entity, param);
    }

    @Override
    public int updateWithNull(SysGenProject entity, SysGenProject param) {
        return sysGenProjectMapper.updateWithNull(entity, param);
    }
}
